﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using LinFu.IoC;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;

namespace CoreEx.Database.Client.Implementation
{
    [Implements(typeof(IConnectionInfoInjector))]
    public class ConnectionInfoInjector : IConnectionInfoInjector, IInitialize
    {
        private IServiceContainer _serviceContainer;

        public void Inject(string name, string providerName, string connectionString)
        {
            _serviceContainer.Inject<IConnectionInfo>(name)
                .Using(
                () =>
                new ConnectionInfo()
                    {
                        Name = name,
                        ProviderName = providerName,
                        ConnectionString = connectionString
                    }).AsSingleton();

            
        }

        public void Initialize(IServiceContainer source)
        {
            _serviceContainer = source;
        }
    }
}
